package day13.demo1.maipiao.demo2;

/**
 * @Auther:小陈的Java
 */
public class WindowTest2 {
    public static void main(String[] args) {
        Runnable runnable = new window2();
        Thread thread1 = new Thread(runnable, "窗口1");
        Thread thread2 = new Thread(runnable, "窗口2");
        Thread thread3 = new Thread(runnable, "窗口3");
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
class window2 implements Runnable {
    private int ticket = 100;
    @Override
    public void run(){
        while (true){
            synchronized (this){
                if(ticket>0){
                    System.out.println(Thread.currentThread().getName()+":卖票，卖第"+ticket+"票");
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    ticket--;
                }else {
                    break;
                }
            }

        }
    }
}
